<?php

/**
 * This is the model class for table "{{job}}".
 *
 * The followings are the available columns in table '{{job}}':
 * @property integer $jobID
 * @property integer $vendorID
 * @property integer $userID
 * @property string $job_title
 * @property string $job_type
 * @property string $job_location
 * @property string $job_description
 * @property string $created
 * @property string $modified
 *
 * The followings are the available model relations:
 * @property Vendor $vendor
 * @property JobApplication[] $jobApplications
 */
class Job extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Job the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{job}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('job_type,job_title,job_location,job_description,enable', 'required'),
			array('vendorID, userID', 'numerical', 'integerOnly'=>true),
			array('job_title', 'length', 'max'=>100),
			array('job_type', 'length', 'max'=>50),
			array('job_location', 'length', 'max'=>200),
			array('job_description, created, modified', 'safe'),
                        array('modified','default',
                             'value'=>new CDbExpression('NOW()'),
                            'setOnEmpty'=>false,'on'=>'update'),
                       array('created,modified','default',
                             'value'=>new CDbExpression('NOW()'),
                              'setOnEmpty'=>false,'on'=>'insert'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('jobID, vendorID, userID, job_title, job_type, job_location, job_description, created, modified', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'vendor' => array(self::BELONGS_TO, 'Vendor', 'vendorID'),
			'jobApplications' => array(self::HAS_MANY, 'JobApplication', 'jobID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'jobID' => 'Job',
			'vendorID' => 'Vendor',
			'userID' => 'User',
			'job_title' => 'Job Title',
			'job_type' => 'Job Type',
			'job_location' => 'Job Location',
			'job_description' => 'Job Description',
                        'enable'=>'Approve',
			'created' => 'Created',
			'modified' => 'Modified',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('jobID',$this->jobID);
		$criteria->compare('vendorID',$this->vendorID);
		$criteria->compare('userID',$this->userID);
		$criteria->compare('job_title',$this->job_title,true);
		$criteria->compare('job_type',$this->job_type,true);
		$criteria->compare('job_location',$this->job_location,true);
		$criteria->compare('job_description',$this->job_description,true);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('modified',$this->modified,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}